/**
 * @author TrinhNX
 */
public class Euler020 {
	public static void main(String[] args) {
		final int MAX = 10000;
		final Integer[] data = new Integer[MAX];
		long start = System.currentTimeMillis();
		System.out.println("START");
		// Initialize the data
		for (int i = 1; i < MAX; i++) {
			// Assign value a[i] = sum of divisor of i
			data[i] = numOfDivisor(i);
		}
		// Well, we loop, we loop :v :v
		int sum = 0;
		for (int i = 1; i < MAX; i++) {
			if (i != 1 && (i != data[i])) {
				if (i == numOfDivisor1(data[i])) {
					System.out.println("got it" + i + "number " + data[i]);
					sum = sum + i + data[i];
				}
			}
		}
		// Because duplicated :v
		System.out.println("Sum before" + sum + "Sum after" + sum / 2);
		System.out.println("END AFTER " + (System.currentTimeMillis() - start));
	}

	/**
	 * Sum of divisor (less than num)
	 * @param num
	 * @return
	 */
	private static int numOfDivisor(final int num) {
		int sum = 1;
		for (int i = (num / 2); i >= 2; i--) {
			if (num % i == 0)
				sum = sum + i;
		}
		return sum;
	}

	private static int numOfDivisor1(final int num) {
		int sqrt = (int) Math.sqrt(num);
		int sum = 1;
		for (int i = 2; i <= sqrt; i++) {
			if (num % i == 0) {
				// LOL, this is so fuckingg tricky :v :v
				sum += i + (num / i == i ? 0 : num / i);
			}
		}
		return sum;
	}
}
